package fr.musique.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


/**
 * Servlet implementation class Template
 */

// A REPRENDRE    A REPRENDRE    A REPRENDRE    A REPRENDRE    A REPRENDRE    A REPRENDRE    A REPRENDRE    A REPRENDRE    A REPRENDRE    A REPRENDRE    A REPRENDRE    A REPRENDRE   //

public class PlaylistServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public PlaylistServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		process(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		process(request, response);
	}

	protected void process(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		RequestDispatcher rd;
		HttpSession session = request.getSession(false);

		String page = request.getPathInfo();

		// Deconnection
		if (page.compareTo("/deco") == 0) {
			session.invalidate();

			rd = request.getRequestDispatcher("/WEB-INF/Login.jsp");
			rd.forward(request, response);
		}
		// Ajout d'une musique
		else if (page.compareTo("/creerPLaylist") == 0) {
			request.setAttribute("page", "CreerPlaylist");
			rd = request.getRequestDispatcher("/WEB-INF/Accueil.jsp");
			rd.forward(request, response);
		}
		// Modifier une musique
		else if (page.compareTo("/listing") == 0) {
			request.setAttribute("page", "Listing");
			rd = request.getRequestDispatcher("/WEB-INF/Accueil.jsp");
			rd.forward(request, response);
		} else if (page.compareTo("/ajoutMusiquePlaylist") == 0) {
			request.setAttribute("page", "AjoutMusiquePlaylist");
			rd = request.getRequestDispatcher("/WEB-INF/Accueil.jsp");
			rd.forward(request, response);
		} else if (page.compareTo("/modifPLaylist") == 0) {
			request.setAttribute("page", "ModifPlaylist");
			rd = request.getRequestDispatcher("/WEB-INF/Accueil.jsp");
			rd.forward(request, response);
		} else if (page.compareTo("/ajoutAlbumPlaylist") == 0) {
			request.setAttribute("page", "AjoutAlbumPlaylist");
			rd = request.getRequestDispatcher("/WEB-INF/Accueil.jsp");
			rd.forward(request, response);
		}
	}
}